// CREATE TABLE `t_order` (
//     `id` int(11) NOT NULL,
//     `oid` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
//     `status` int(255) DEFAULT NULL COMMENT '0 待支付 1待发货 2已发货 3已签收 4已取消',
//     `goods_ids` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '商品',
//     `shipping_address` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '收货地址',
//     `recevier_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '收货人姓名',
//     `recevier_phone` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '收货人电话',
//     `actual_fee` float(255,0) DEFAULT NULL COMMENT '实付金额',
//     `create_date` datetime DEFAULT NULL COMMENT '创建日期',
//     `update_date` datetime DEFAULT NULL COMMENT '修改日期',
//     PRIMARY KEY (`id`,`oid`)
//   ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci



let { v4: uuidv4 } = require("uuid")
const knex = require("../dao")
let TNAME = 't_order'
class Order {
    Add = (data, callback) => {
        data.oid = uuidv4()
        knex(TNAME).insert(data).then(res => {
            callback(undefined, { code: 200, msg: "success", data: {} })
        }).catch(err => {
            callback(undefined, { code: 500, msg: err, data: {} })
        })
    }
    Update = (data, callback) => {
        let { oid } = data
        knex(TNAME).where({ oid }).update(data).then(res => {
            callback(undefined, { code: 200, msg: "success", data: {} })
        }).catch(err => {
            callback(undefined, { code: 500, msg: err, data: {} })
        })
    }
    List = ({ page, page_size }, callback) => {
        knex(TNAME).select().limit(page_size || 10).offset(page || 0).then(res => {
            callback(undefined, { code: 200, msg: "", data: res })
        }).catch(err => {
            callback(undefined, { code: 500, msg: err, data: {} })
        })
    }
    Detail = ({ oid }, callback) => {
        knex(TNAME).select().where({ oid }).then(res => {
            callback(undefined, { code: 200, msg: "", data: res })
        }).catch(err => {
            callback(undefined, { code: 500, msg: err, data: {} })
        })
    }

}

module.exports = Order